<?php
/**
 * Path is a list (Yz_Array) of Category items
 *
 */
namespace Dclub\modules\Catalog;

class Model_TreePath
    extends \Yz\modules\Generic\Model_List
{


    /**
     *  a name of item class (Yz_Item_Interface)
     *  @var string
     */
    protected $itemName = "Category";


    /************************************
     *      Public methods
     ************************************/

    /** fetch the path of a tree node
     *
     *  @return Yz_Array{category}
     */
    public function fetchCategoryPath($nodeId)
    {
        debug();
        return $this->_fetchListWithAction(
                null,
                'SelectTreePath',
                function($action) use ($nodeId) {
                    $action->setNodeId($nodeId);
                    return $action();
                }
            )
        ;
    }

    /** fetch the path of a tree node
     *
     *  @return Yz_Array{category}
     */
    public function fetchItemPath($itemId)
    {
        debug();

        return $this->_fetchListWithAction(
                null,
                'SelectTreePath',
                function($action) use ($itemId) {
                    $action->setItemId($itemId);
                    return $action();
                }
            )
        ;
    }

    /** fetch the path of a tree node
     *
     *  @return Yz_Array{category}
     */
    public function fetchPathByNames($names)
    {
        debug();

        return $this->_fetchListWithAction(
                null,
                'SelectTreePathByNames',
                function($action) use ($names) {
                    $action->setNames($names);
                    return $action();
                }
            )
        ;
    }


    /************************************
     *       Protected methods          *
     ************************************/

    /** override parent and return Yz_Array instead of Yz_Hash
     *
     *
     */
    protected function assignValues($values, $item)
    {
        if (null === $values) {
            return new \Yz_Array();
        }
        $list = array();
        foreach ($values as $value) {
            $item0 = clone $item;
            $list[] = $item0->assignValues($value);
        }
        return new \Yz_Array($list);
    }

}
